package io.aio;

import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousSocketChannel;
import java.nio.channels.CompletionHandler;

/**
 *@Description:<p>获取客户端连接后的回调处理器</p>
 *@author 王旭
 *@time 2016年3月17日 下午9:06:43
 */
public class AcceptCompletionHandler implements CompletionHandler<AsynchronousSocketChannel, TimeServerHandler> {

	public void completed(AsynchronousSocketChannel result,
			TimeServerHandler attachment) {
		attachment.serverSocketChannel.accept(attachment, this);
		
		ByteBuffer buffer = ByteBuffer.allocate(1024);
		result.read(buffer, buffer, new ReadCompletionHandler(result));
		
	}

	public void failed(Throwable exc, TimeServerHandler attachment) {
		attachment.latch.countDown();
	}
	
}
